package com.hwx.controller;

import com.hwx.feign.IMemberCommonFeign;
import com.hwx.feign.IMemberFeign;
import com.hwx.pojo.Member;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.List;

@RestController
public class OrderController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private IMemberFeign iMemberFeign;

    /**
     * 应用API的  Feign
     */
    @Autowired
    private IMemberCommonFeign iMemberCommonFeign;

    @RequestMapping("/getOrder")
    public String getOrder(){

        String forObject = restTemplate.getForObject("http://app-hwx-member/getMember", String.class);
        return "订单调用会员系统:"+forObject;
    }


    @RequestMapping("/getOrderFeign")
    public String getOrderFeign(){
          return "订单调用会员系统:"+iMemberCommonFeign.getMember();
    }


    @RequestMapping("/getMemberListFeign")
    public List<Member> getMemberList(){
        return iMemberFeign.getMemberList();
    }


    @RequestMapping("/getMemberById")
    public String getMemberById(Integer id){
        return iMemberFeign.getMemberById(id);
    }

    @RequestMapping("/addMember")
    public void addMember(Member member){
        System.out.println("-*********************************");
        System.out.println(member);
        System.out.println("-*********************************");
        iMemberFeign.addMember(member);
    }


    /**
     * 服务熔断的演示方法
     * @param id
     * @return
     */
    @RequestMapping("/getMemberById2")
    public Member getMemberById2(Integer id){
        return iMemberFeign.getMemberById2(id);
    }

}
